#ifndef CHECKBOXDELEGATE_H
#define CHECKBOXDELEGATE_H

#include "comui_global.h"

#include <QStyledItemDelegate>
#include <QHeaderView>
#include <QCheckBox>

class COMUISHARED_EXPORT CheckBoxDelegate:public QStyledItemDelegate
{
    Q_OBJECT
public:
    CheckBoxDelegate(QObject *parent, int column);
    ~CheckBoxDelegate();
    // painting
    void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const;

protected:
    bool editorEvent(QEvent *event, QAbstractItemModel *model,
                     const QStyleOptionViewItem &option, const QModelIndex &index);

private:
    int m_delegateColumn;
    QScopedPointer<QCheckBox> m_checkBox;
};

class COMUISHARED_EXPORT TableHeaderView:public QHeaderView
{
    Q_OBJECT
public:
    TableHeaderView(Qt::Orientation orientation, QWidget *parent, int column);
    ~TableHeaderView();

protected:
    void paintSection(QPainter *painter, const QRect &rect, int logicalIndex) const;
    bool event(QEvent *e) Q_DECL_OVERRIDE;
    void mousePressEvent(QMouseEvent *e) Q_DECL_OVERRIDE;
    void mouseReleaseEvent(QMouseEvent *e) Q_DECL_OVERRIDE;

public slots:
    void onStateChanged(int state);

signals:
    void stateChanged(int state);

private:
    bool m_bPressed;
    bool m_bChecked;
    bool m_bTristate;
    bool m_bNoChange;
    bool m_bMoving;

private:
    int m_delegateColumn;
    QScopedPointer<QCheckBox> m_checkBox;
};

#endif // CHECKBOXDELEGATE_H
